// pages/tool/card/index/preview/preview.js
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showtips:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        app.func.getPromise('/cardtype/carddetail/' + options.id)
            .then(([code, res]) => {
                if (res.data['a_pic'] == null) {
                    this.setData({
                        showtips:true
                    });
                } else {
                    if (res.data.coupon_type != 2) {
                        this.setData({cardinfo: res.data});
                    } else {
                        let urls = res.data.volume;
                        urls.unshift(res.data['b_pic']);
                        urls.unshift(res.data['a_pic']);
                        this.setData({
                            cardinfo: res.data,
                            urls: urls
                        });
                    }
                }
            })
    },


    preview: function (e) {
        let index = e.currentTarget.dataset.index;
        let current;
        if (index == 0) {
            current = this.data.cardinfo['a_pic'];
        } else {
            current = this.data.cardinfo['b_pic'];
        }
        wx.previewImage({
            current: current,
            urls: [this.data.cardinfo['a_pic'], this.data.cardinfo['b_pic']]
        })
    },

    preview1: function (e) {
        let src = e.currentTarget.dataset.src;
        let urls = this.data.cardinfo.volume;
        wx.previewImage({
            current: src,
            urls: urls
        })
    },

    cancel:function(){
        wx.navigateBack({
            delta:1
        })
    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
